//
//  AppDelegate.m
//  CareGiver
//
//  Created by Guillermo Moral on 7/30/14.
//  Copyright (c) 2014 Humana. All rights reserved.
//

#import "AppDelegate.h"

@interface AppDelegate()

-(void)resetWindows;

@end


@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [self resetWindows];
    return YES;
}

- (void)resetWindows {
    
    if(!self.window) {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen]bounds]];
    }
    
    UIStoryboard *menu = [UIStoryboard storyboardWithName:@"Menu" bundle:[NSBundle mainBundle]];
    self.viewController = [menu instantiateInitialViewController];
    
    [UIView transitionWithView:self.window
                      duration:1
                       options:UIViewAnimationOptionTransitionFlipFromRight
                    animations:^{
                        self.window.rootViewController = self.viewController;
                    }
                    completion:nil];
    
    [self.window makeKeyAndVisible];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    [self.window endEditing:YES];
    
    application.keyWindow.hidden = NO;
    self.imageView = [[UIImageView alloc]initWithFrame:[application.keyWindow frame]];
    [self.imageView setImage:[UIImage imageNamed:@"Defaul-568h@2x.png"]];
    [application.keyWindow addSubview:self.imageView];
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    application.keyWindow.hidden = NO;
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    [self.window makeKeyAndVisible];
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    if(self.imageView!=nil) {
        [self.imageView removeFromSuperview];
        self.imageView = nil;
    }
    
    [self.window makeKeyAndVisible];
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
